package br.com.sales.hanforpi.client.view;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import br.com.sales.hanforpi.client.presenter.HanForPIPresenter;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.KeyboardListenerAdapter;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.ViewWithUiHandlers;

/**
 *
 * @author v
 */
public class HanForPIView
        extends ViewWithUiHandlers<HanForPIPresenter>
        implements HanForPIPresenter.Display {

    private final static MyMainLayoutViewUiBinder uiBinder = GWT.create(MyMainLayoutViewUiBinder.class);
    @UiField
    HTMLPanel container;
    @UiField
    TextBox nmUser;
    @UiField
    TextBox password;
    @UiField
    Label msgError;
    @UiField
    Button btnSend;

    @Inject
    public HanForPIView() {
        container = uiBinder.createAndBindUi(this);
    }

    @Override
    public Widget asWidget() {
        return container;
    }

    @Override
    public void buildView() {
        msgError.setVisible(false);
        onEnterPress();
    }

    @Override
    public Label getMsgError() {
        return msgError;
    }

    @Override
    public TextBox getNmUser() {
        return nmUser;
    }

    @Override
    public TextBox getPassword() {
        return password;
    }

    @UiHandler("btnSend")
    public void onClickEntry(ClickEvent e) {
        getUiHandlers().onClik();
    }

    @UiHandler("btnCancel")
    public void onClickCancel(ClickEvent e) {
        nmUser.setText("");
        password.setText("");
    }

    public void onEnterPress() {
        password.addKeyboardListener(new KeyboardListenerAdapter() {
            @Override
            public void onKeyDown(Widget arg0, char keyCode, int arg2) {
                if (keyCode == KEY_ENTER) {
                   btnSend.click();
                }
            }
        });
    }

    @Override
    public void setUiHandlers(HanForPIPresenter uiHandlers) {
        super.setUiHandlers(uiHandlers);
    }

    interface MyMainLayoutViewUiBinder extends UiBinder<HTMLPanel, HanForPIView> {
    }

}
